<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_design extends CI_Controller {

    private $per_page = '';
    private $total_rows = 6;
    private $uri_page = '';
    private $base_page = '';
    private $uri_segment = '';
    private $thongbao = '';

    function __construct() {
        parent::__construct();
    }

    public function index() {
        $getAlias = $this->common_model->getdata('alias', array('type' => 'sanpham'));
        foreach ($getAlias as $ali) {
            $dataAliastt[$ali->a_id] = $ali;
        }
        $offset = $this->uri->segment(2);
        $this->per_page = 15;
        $this->base_page = $this->uri->segment(1) . '/';
        $this->uri_segment = 2;
        $selectProduct = $this->common_model->getdata('sanpham', array('publish' => 1, 'success' => 0), '', array('id', 'DESC'), array($this->per_page, $offset));
        $this->total_rows = $this->common_model->getnumrow('sanpham', array('success', 0), array('publish' => 1));
        $this->phantrang();

        $offset = $this->uri->segment(2);
        $this->per_page = 15;
        $this->base_page = $this->uri->segment(1) . '/';
        $this->uri_segment = 2;
        $selectProductWorking = $this->common_model->getdata('sanpham', array('publish' => 1, 'success' => 1), '', array('id', 'DESC'), array($this->per_page, $offset));
        $this->total_rows = $this->common_model->getnumrow('sanpham', array('success', 1), array('publish' => 1));
        $this->phantrang();

        $offset = $this->uri->segment(2);
        $this->per_page = 15;
        $this->base_page = $this->uri->segment(1) . '/';
        $this->uri_segment = 2;
        $selectProductSuccess = $this->common_model->getdata('sanpham', array('publish' => 1, 'success' => 2), '', array('id', 'DESC'), array($this->per_page, $offset));
        $this->total_rows = $this->common_model->getnumrow('sanpham', array('success', 2), array('publish' => 1));
        $this->phantrang();
        $dataArrPro = array(
            'selectProduct' => $selectProduct,
            'selectProductWorking' => $selectProductWorking,
            'selectProductSuccess' => $selectProductSuccess,
            'dataAliastt' => $dataAliastt
        );
        $data['title'] = 'Kho giao diện';
        $data['metades'] = 'Kho giao diện';
        $data['metakey'] = 'Kho giao diện';
        $data['content'] = $this->load->view('mod_design/views_content', $dataArrPro, true);
        $this->load->view('homepage', $data);
    }

    public function getListProduct($idProduct, $aliasProduct) {
        $getCateAlias = $this->common_model->getdata('alias', array('type' => 'danhmucsp'));
        foreach ($getCateAlias as $ali) {
            $dataAlias[$ali->a_id] = $ali;
        }
        $getAlias = $this->common_model->getdata('alias', array('type' => 'sanpham'));
        foreach ($getAlias as $ali) {
            $dataAliastt[$ali->a_id] = $ali;
        }
        $menu = $this->common_model->getdata('danhmucsp', array('publish' => 1));
        foreach ($menu as $mn) {
            $pcat[$mn->parentid][] = $mn;
            $pcat1[$mn->id] = $mn;
        }
        $categories = $this->common_model->getone('danhmucsp', array('id' => $idProduct));
        $mang = $this->common_model->getcat($pcat, $idProduct, array());
        $mcat = $this->common_model->category_tt1($idProduct, $pcat1, array());
        if (!empty($mang)) {
            $offset = $this->uri->segment(2);
            $this->per_page = 12;
            $this->base_page = $this->uri->segment(1) . '/';
            $this->uri_segment = 2;
            $getDataProduct = $this->common_model->getlist('sanpham', array('category', $mang), array('publish' => 1, 'success' => 0), '', array('id', 'DESC'), array($this->per_page, $offset));
            $this->total_rows = $this->common_model->getnumrow('sanpham', array('category', $mang), array('publish' => 1, 'success' => 0));
            $this->phantrang();
            if (!empty($getDataProduct)) {
                $dataArrPro = array(
                    'getDataProduct' => $getDataProduct,
                    'categories' => $categories,
                    'dataAlias' => $dataAlias,
                    'dataAliastt' => $dataAliastt
                );
                $data['content'] = $this->load->view('mod_design/list_design', $dataArrPro, true);
            } else {
                $data['content'] = $this->load->view('view_404', '', true);
            }
        } else {
            $data['content'] = $this->load->view('view_404', '', true);
        }
        if ($categories->title_seo != '') {
            $data['title'] = $categories->title_seo;
        } else {
            $data['title'] = $categories->title;
        }
        $data['metades'] = $categories->metades;
        $data['metakey'] = $categories->metakey;
        $this->load->view('homepage', $data);
    }

    public function detail($id, $aliasCategories) {
        $news = $this->common_model->getone('sanpham', array('publish' => 1, 'id' => $id));
        $getAlias = $this->common_model->getdata('alias', array('type' => 'sanpham'));
        foreach ($getAlias as $ali) {
            $dataAliastt[$ali->a_id] = $ali;
        }
        $getCateAlias = $this->common_model->getdata('alias', array('type' => 'danhmucsp'));
        foreach ($getCateAlias as $ali) {
            $dataAlias[$ali->a_id] = $ali;
        }
        if (!empty($news)) {
            $cat = $this->common_model->getone('danhmucsp', array('publish' => 1, 'id' => $news->category));
            $menu = $this->common_model->getdata('danhmucsp', array('publish' => 1));
            foreach ($menu as $mn) {
                $pcat[$mn->parentid][] = $mn;
                $pcat1[$mn->id] = $mn;
            }
            $mang = $this->common_model->getcat($pcat, $cat->id, array());
            $mcat = $this->common_model->category_tt1($cat->id, $pcat1, array());
            $tinlq = $this->common_model->getlist('sanpham', array('category', $mang), array('publish' => 1, 'id <' => $news->id), '', array('id', 'DESC'), 6);
            $data['title'] = $news->title_seo;
            $data['metades'] = $news->metades;
            $data['metakey'] = $news->metakey;
            $data['content'] = $this->load->view('mod_design/detail', array('product' => $news, 'mcat' => $mcat, 'prollq' => $tinlq, 'dataAliastt' => $dataAliastt, 'dataAlias' => $dataAlias), true);
        } else {
            $data['title'] = 'Error 404';
            $data['metades'] = 'Error 404';
            $data['metakey'] = 'Error 404';
            $data['content'] = $this->load->view('view_404', '', true);
        }
        $this->load->view('homepage', $data);
    }

    function demo() {
        $data['title'] = 'Error 404';
        $data['metades'] = 'Error 404';
        $data['metakey'] = 'Error 404';
        $data['content'] = $this->load->view('view_404', '', true);
        $this->load->view('homepage', $data);
    }

    function phantrang() {
        $this->load->library('pagination');
        $config['base_url'] = base_url() . $this->base_page;
        $config['total_rows'] = $this->total_rows;
        $config['per_page'] = $this->per_page;
        $config['uri_segment'] = $this->uri_segment;
        $config['num_links'] = 12;
        $this->pagination->initialize($config);
    }

}
